﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.PackageManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.PackageManagement.PackageRecordVMs
{
    public partial class PackageRecordListVM : BasePagedListVM<PackageRecord_View, PackageRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<PackageRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<PackageRecord_View>>{
                
                this.MakeGridHeader(x => x.PackageRecord_Package).SetTitle(@Localizer["Page.包装箱"].Value),
                this.MakeGridHeader(x => x.PackageRecord_WoId).SetTitle(@Localizer["Page.工单"].Value),
                this.MakeGridHeader(x => x.PackageRecord_WoCode).SetTitle(@Localizer["Page.工单编码"].Value),
                this.MakeGridHeader(x => x.PackageRecord_ProductId).SetTitle(@Localizer["Page.装箱产品"].Value),
                this.MakeGridHeader(x => x.PackageRecord_ProductName).SetTitle(@Localizer["Page.产品名称"].Value),
                this.MakeGridHeader(x => x.PackageRecord_Sn).SetTitle(@Localizer["Page.装箱条码"].Value),
                this.MakeGridHeader(x => x.PackageRecord_PartSn).SetTitle(@Localizer["Page.产品条码"].Value),
                this.MakeGridHeader(x => x.PackageRecord_StartTime).SetTitle(@Localizer["Page.首次装箱时间"].Value),
                this.MakeGridHeader(x => x.PackageRecord_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.PackageRecord_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<PackageRecord_View> GetSearchQuery()
        {
            var query = DC.Set<PackageRecord>()
                
                .CheckEqual(Searcher.PackageId, x=>x.PackageId)
                .CheckEqual(Searcher.WoId, x=>x.WoId)
                .CheckContain(Searcher.WoCode, x=>x.WoCode)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckContain(Searcher.ProductName, x=>x.ProductName)
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckContain(Searcher.PartSn, x=>x.PartSn)
                .CheckBetween(Searcher.StartTime?.GetStartTime(), Searcher.StartTime?.GetEndTime(), x => x.StartTime, includeMax: false)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .Select(x => new PackageRecord_View
                {
				    ID = x.ID,
                    
                    PackageRecord_Package = x.Package.TenantCode,
                    PackageRecord_WoId = x.WoId,
                    PackageRecord_WoCode = x.WoCode,
                    PackageRecord_ProductId = x.ProductId,
                    PackageRecord_ProductName = x.ProductName,
                    PackageRecord_Sn = x.Sn,
                    PackageRecord_PartSn = x.PartSn,
                    PackageRecord_StartTime = x.StartTime,
                    PackageRecord_Remark = x.Remark,
                    PackageRecord_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class PackageRecord_View: PackageRecord
    {
        
        public string PackageRecord_Package { get; set; }
        public long? PackageRecord_WoId { get; set; }
        public string PackageRecord_WoCode { get; set; }
        public long? PackageRecord_ProductId { get; set; }
        public string PackageRecord_ProductName { get; set; }
        public string PackageRecord_Sn { get; set; }
        public string PackageRecord_PartSn { get; set; }
        public DateTime? PackageRecord_StartTime { get; set; }
        public string PackageRecord_Remark { get; set; }
        public bool PackageRecord_IsValid { get; set; }

    }

}